package mn.idax.exchange.otc.util;

import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @Auther: dison
 * @Date: 2018/9/11 13:35
 * @Description:
 */
public class MongoDBQueryUtils {

    public static void buildQueryEqualTo(Query query,Object ...obj){
        for (int i = 0; i < obj.length; i++) {
            if (i % 2 == 0) {
                query.addCriteria(Criteria.where(obj[i].toString()).is(obj[i + 1]));
            }
        }
    }

    public static void buildQuerySortDesc(Query query,Object ...obj){
        for (int i = 0; i < obj.length; i++) {
            query.with(new Sort(Sort.Direction.DESC, obj[i].toString()));
        }
    }

    public static void buildQuerySortAsc(Query query,Object ...obj){
        for (int i = 0; i < obj.length; i++) {
            query.with(new Sort(Sort.Direction.DESC, obj[i].toString()));
        }
    }
}
